package com.java.springcloud.mybatisplus.idgenerator;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.stereotype.Component;

/**
 * @Author zhangtao
 * @create 2023/2/17 16:28
 */
@Component
public class CustomIdentifierGenerator implements IdentifierGenerator {
    private final Sequence sequence;

    public CustomIdentifierGenerator(InetUtils inetUtils) {
        this.sequence = new Sequence(inetUtils.findFirstNonLoopbackAddress());
    }

    @Override
    public Long nextId(Object entity) {
        return sequence.nextId();
    }
}
